package com.homework.exam02.Config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;

import java.util.Objects;

@SuppressWarnings("unused")
class CustomCommandLineRunner implements CommandLineRunner {

    @Autowired
    Environment env;


    //使用构造方法的方式，注入Environment
    public CustomCommandLineRunner(Environment env){
        this.env = env;
    }

    @Override
    public void run(String... args) throws Exception {
        System.out.println("利用Springboot自动装配的CommandLineRunner.");

        //利用random的RandomValuePropertySource产生一个32位的随机数
        System.out.println("生成一个随机字符串：".concat(Objects.requireNonNull(env.getProperty("random."))));
    }
}